<%-- 
    Document   : editdetail
    Created on : Apr 20, 2012, 1:24:02 PM
    Author     : prateekpatil
--%>

<%@page import="java.sql.*"%>
<%@page import="cs425proj.model.MemberDetail" %>


 <%
        response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
        response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
        response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
        response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
        %>
        <%String name = (String) session.getAttribute("name");%>
        <% if (null == name) { %>
        <html>
            <META HTTP-EQUIV="refresh" CONTENT="5; URL=http://localhost:8084/cs425proj/">
   <body >
        <table align="center">
            <thead>
                <tr>
                     <h1> CS 425 Project </h1>
                </tr>
            </thead>
        </table>
       <table align="center">
            <thead>
                <tr>
                    <th><h3>
                        SESSION EXPIRED.<br/>
                        You will be directed to home page in 5 sec.<br/>
                        <img src="spin_loader.gif" width="54" height="55" alt="spin_loader"/><br/>
                        If you aren't forwarded to the new page,<a href="http://localhost:8084/cs425proj/"> click here</a>.
                        
                    </h3></th>
                </tr>
            </thead>
        </table>
       
   </body>
</html>
<%    }%>
<% if (name != null) { %>
<!DOCTYPE html>
<html>
   
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script type="text/javascript">
            $(function() {
                initCountry();
                
            });
            
            function initCountry(response) {
                initSelectHierarchy('country','state.jsp','state-wrapper',initState);
            }
            function initState(response) {
                initSelectHierarchy('state','city.jsp','city-wrapper',initCity);
                
            }
            function initCity(response) {
                initSelectHierarchy('city','list.jsp','list-wrapper',function(res) {
                    //alert('List response: '+res);
                });
            }
            
            function initSelectHierarchy(selectBoxId, jspFile, childWrapperId, successFunc) {
                $('#'+selectBoxId).change(function() {
                    var val = $(this).val();
                    //alert('Country: '+country);
                    $.ajax({
                        method: 'GET',
                        url: jspFile,
                        data: {'count':val},
                        success: function(responseHtml) {
                            //alert(html);
                            $('#'+childWrapperId).html(responseHtml);
                            successFunc.call(responseHtml);
                            //successFunc();
                        },
                        failure: function() {
                            alert('Unable to get data.');
                        }
                    });
                });
            }
        </script>
    </head>
                    
    <body>
       
        <table align="center">
            <thead>
                <tr>
                    <th><h1>CS 425 Project </h1></th>
                </tr>
            </thead>
        </table>
        <table border="1" width="900"  align="center" >
             <tbody>
                <tr>
                    <td width="450"  border="1">     
                        <p> selecting movies </p> 
                        <table  align="center">
                            <tr><td>
                                    <table><tr>
                                            <td>
                                    <div id="country-wrapper">
                                    <select name='country' id="country"><!-- onchange="showState(this.value)">  -->
                        <option value="none">Select</option>  
        
                        <%
                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
                    Connection con1 = DriverManager.getConnection("jdbc:oracle:thin:@fourier.cs.iit.edu:1521:orcl","ppatil2","bosu8525");  
                    Statement stmt1= con1.createStatement();  
                    ResultSet rs1 = stmt1.executeQuery("Select * from country");
                    while(rs1.next()){
                        %>
                        <option value="<%=rs1.getString(1)%>"><%=rs1.getString(2)%></option>  
                        <%
                    }
                        %>
                        </select>  
                                    </div>
                                            </td>
                                            <td><div id='state-wrapper'></div>  </td>
                                            <td><div id='city-wrapper'></div></td>
                                            
                                        </tr></table>
                        <div id='list-wrapper'></div>
                                </td></tr>
                                <tr><td>  
                                    <div id='list'> 
                                        <p name='list'>
                                        </p>
                                    </div>
                                </td></tr>
                                
                       </table>
                </td>
                    <td width="450" bgcolor="#efefef" >
                        <table  align="center">
                            <tr>
                                <td>
                                    
                                   <%
                    MemberDetail obj = new MemberDetail();
                    obj.selectMemberData(name);
                      %>
                     <form action="EditDetail" method=post>
                        <table cellpadding=4 cellspacing=2 border=0 align="center" width="400" >
                        <th bgcolor="#efefef" colspan=2>
                        <font size=5>Edit detail</font>
                        <br><font size=1><sup></sup></font><hr>
                        </th><tr bgcolor="#efefef"><td valign=top> 
                        <b>First Name<sup>*</sup></b> 
                        <br><input type="text" name="firstname" value="<%=obj.getF_name()%>" size=25 maxlength=20 readonly="readonly">
                        </td><td valign=top><b>Last Name<sup>*</sup></b>
                        <br><input type="text" name="lastname" value="<%=obj.getL_name()%>" size=15 maxlength=20 readonly="readonly"></td>
                        </tr>
                        <tr bgcolor="#efefef">
                        <td valign=top><b>E-Mail<sup>*</sup></b> 
                        <br><input type="text" name="email" value="<%=obj.getEmail()%>" size=25 
                        maxlength=125><br></td><td valign=top>
                        <b>Phone<sup>*</sup></b> <br>
                        <input type="text" name="phone" value="<%=obj.getPhone()%>" size=15 maxlength=11></td>
                        </tr>
                        <tr bgcolor="#efefef"><td valign=top colspan=2>
                        <b>User Name<sup>*</sup></b><br>
                        <input type="text" name="userId" size=25 value="<%=obj.getUsername()%>" maxlength=10 readonly="readonly">
                        </td></tr>
                        <tr bgcolor="#efefef">
                        <td valign=top><b>Member Type<sup>*</sup></b> 
                            <br><input type="member_type" name="Member Type" size=10 value="<%=obj.getMember_type()%>" readonly="readonly" 
                        maxlength=10></td><td valign=top>
                        <b>Rewards Point<sup>*</sup></b>
                        <br><input type="rewardpoint" name="rewardpoint" size=10 value="<%=(obj.getTotal_points()-obj.getPoints_spent())%>" readonly="readonly" 
                        maxlength=10></td><br>
                        </tr>
                        <tr bgcolor="#efefef">
                        <td valign=top>
                        <b>Address:<sup>*</sup></b>
                        <br><input type="text" name="address" size=25 value="<%=obj.getAddress()%>" 
                                maxlength=100></td>
                        <br>
                        <td valign=top>
                        <b>City:<sup>*</sup></b>
                        <br><input type="text" name="city" size=5 value="<%=obj.getCity()%>" maxlength=10></td>
                        </tr>
                        <tr bgcolor="#efefef">
                        <td valign=top>
                        <b>State:<sup>*</sup></b>
                        <br><input type="text" name="state" size=10 value="<%=obj.getState()%>" 
                        maxlength=10></td><br>
                        <td valign=top>
                        <b>Zip:<sup>*</sup></b>
                        <br><input type="text" name="zip" size=10 value="<%=obj.getZipcode()%>" 
                        maxlength=10></td>
                        </tr>
                        <tr bgcolor="#efefef">
                        <td align=center colspan=2><hr>
                        <input type=submit name="editdetail" value="Save"></input></td>
                        </tr>
                        
                        </table>

                </form>
                      
                      
                        <form method=get action="ForwardServlet">
                            <input type=submit value=Cancel></input>
                        </form>
                                            
                        
                     
                       
                                    
                                </td>
                               
                           </tr>
                           </table>
        </table>
            
           
    </body>
     
</html>
<%}%>